<template>
  <div id="center">
    <div class="up">
      <div class="bg-color-black item" v-for="item in titleItem" :key="item.title">
        <p class="ml-3 colorBlue fw-b" :title="item.title">{{item.title}}</p>
        <div>
          <dv-digital-flop :config="item.number" style="width:100%;height:.625rem;display:inline-block;margin-top:0.2rem;" />
        </div>
      </div>
    </div>
    <!-- <div class="down">
      <div class="ranking bg-color-black">
        <span style="color:#5cd9e8">
          <icon name="align-left"></icon>
        </span>
        <span class="fs-xl text mx-2 mb-1">年度负责人组件达标榜</span>
        <dv-scroll-ranking-board :config="ranking" style="height:2.75rem" />
      </div>
      <div class="percent">
        <div class="item bg-color-black">
          <span>今日任务通过率</span>
          <centerChart :id="rate[0].id" :tips="rate[0].tips" :colorObj="rate[0].colorData" />
        </div>
        <div class="item bg-color-black">
          <span>今日任务达标率</span>
          <centerChart :id="rate[1].id" :tips="rate[1].tips" :colorObj="rate[1].colorData" />
        </div>
        <div class="water">
          <dv-water-level-pond :config="water" style="height: 1.5rem" />
        </div>
      </div>
    </div> -->
  </div>
</template>

<script>
import centerChart from '@/cuscomponents/echart/center/centerChartRate'
import { createNamespacedHelpers } from 'vuex'
const { mapState } = createNamespacedHelpers('screen')

export default {
  data () {
    return {
      titleItem: [
        {
          title: this.$t('B7hgWZ-ZSurAsJJvV9AIe') + '(kWh)',
          number: {
            number: [0],
            toFixed: 2,
            // content: '{nt} kWh'
            content: '{nt} '

          }
        },
        {
          title: this.$t('jhOHkzJphJwwP6j_SH81R') + '(kWh)',
          number: {
            number: [0],
            toFixed: 2,
            // content: '{nt} kWh'
            content: '{nt} '

          }
        },
        {
          title: this.$t('DL2DNclHzKS40EZ3cpZlV'),
          number: {
            number: [0],
            toFixed: 0,
            // content: '{nt} ' + this.$t('gvvbCXhgboLNspUiEBq7s')
            content: '{nt} '

          }
        },
        {
          title: this.$t('XjkvBxfjJwf393WOosUZ1'),
          number: {
            number: [0],
            toFixed: 0,
            // content: '{nt} ' + this.$t('gvvbCXhgboLNspUiEBq7s')
            content: '{nt} '

          }
        },
        {
          title: this.$t('FYADU6PNiO1NdZhqGdMaf') + '(' + this.$t('rEwoS7D6EkR6EPGHSq6MU') + ')',
          number: {
            number: [0],
            toFixed: 2,
            // content: '{nt} ' + this.$t('rEwoS7D6EkR6EPGHSq6MU')
            content: '{nt} '

          }
        },
        {
          title: this.$t('YIw5pcCE-vz_dj--a6qEb') + '(' + this.$t('rEwoS7D6EkR6EPGHSq6MU') + ')',
          number: {
            number: [0],
            toFixed: 2,
            // content: '{nt} ' + this.$t('rEwoS7D6EkR6EPGHSq6MU')
            content: '{nt} '

          }
        },
        {
          title: this.$t('NAY4nNIopam8LHw8OIX1k') + '(' + this.$t('I4guWEhjHUQJA5FgWQzKM') + ')',
          number: {
            number: [0],
            toFixed: 0,
            // content: '{nt} ' + this.$t('rEwoS7D6EkR6EPGHSq6MU')
            content: '{nt} '

          }
        },
        {
          title: this.$t('KSebDSGUPQi7vX4iugxek') + '(' + this.$t('I4guWEhjHUQJA5FgWQzKM') + ')',
          number: {
            number: [0],
            toFixed: 0,
            // content: '{nt} ' + this.$t('rEwoS7D6EkR6EPGHSq6MU')
            content: '{nt} '

          }
        }
      ]
    }
  },
  computed: {
    ...mapState(['operatorScreenData'])
  },
  mounted () {
    this.makeData()
  },
  watch: {
    'operatorScreenData.detail': {
      handler: function () {
        this.makeData()
      },
      deep: true
    }
  },
  methods: {
    makeData () {
      this.titleItem = this.titleItem.map((item, index) => {
        const it = _.cloneDeep(item)
        if (index == 0) {
          it.number.number = [this.operatorScreenData.detail.today_elec]
        } else if (index == 1) {
          it.number.number = [this.operatorScreenData.detail.total_elec]
        } else if (index == 2) {
          it.number.number = [this.operatorScreenData.detail.today_count]
        } else if (index == 3) {
          it.number.number = [this.operatorScreenData.detail.total_count]
        } else if (index == 4) {
          it.number.number = [this.operatorScreenData.detail.today_amount]
        } else if (index == 5) {
          it.number.number = [this.operatorScreenData.detail.total_amount]
        } else if (index == 6) {
          it.number.number = [this.operatorScreenData.detail.today_usetimes]
        } else if (index == 7) {
          it.number.number = [this.operatorScreenData.detail.total_usetimes]
        }
        // it.number.number = [123456789]
        const num = it.number.number[0]
        it.number.style = this.transformStyle({ num })
        return it
      })
    },
    transformStyle ({ num }) {
      const style = {
        fontSize: 30
      }
      if (num) {
        const n = 32
        const length = String(num).length
        _.assign(style, { fontSize: _.max([n - 1 * length, 10]) })
      }
      return style
    }
  },
  components: {
    centerChart
    // centerChart1,
    // centerChart2
  }
}
</script>

<style lang="scss" scoped>
#center {
  display: flex;
  flex-direction: column;
  .up {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    padding: 0.1rem;
    .item {
      border-radius: 0.0625rem;
      padding: 0.2rem;
      margin: 0.1rem;
      width: 43%;
      height: 1.22rem;
      p {
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
      }
    }
  }
  .down {
    padding: 0.07rem 0.05rem;
    padding-bottom: 0;
    width: 100%;
    display: flex;
    height: 3.1875rem;
    justify-content: space-between;
    .bg-color-black {
      border-radius: 0.0625rem;
    }
    .ranking {
      padding: 0.125rem;
      width: 59%;
    }
    .percent {
      width: 40%;
      display: flex;
      flex-wrap: wrap;
      .item {
        width: 50%;
        height: 1.5rem;
        span {
          margin-top: 0.0875rem;
          display: flex;
          justify-content: center;
        }
      }
      .water {
        width: 100%;
      }
    }
  }
}
</style>
